package cn.itcast.search.controller;

import cn.itcast.hmall.dto.common.PageDTO;
import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.hmall.dto.search.SearchReqDTO;
import cn.itcast.hmall.pojo.item.ItemDoc;
import cn.itcast.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/search")
@RestController
public class SearchController {
    @Autowired
    private SearchService searchService;
    @GetMapping("/importItemData")
    public ResultDTO importSource(){
       return searchService.importSource();
    }
    @GetMapping("/suggestion")
    public List<String> autoComplete(@RequestParam("key") String param){
        return searchService.autoComplete(param);
    }
    @PostMapping("/filters")
    public Map<String,List<String>> getFilters(@RequestBody SearchReqDTO param){
        return searchService.getFilters(param);
    }
    @PostMapping("list")
    public PageDTO<ItemDoc> basicFind(@RequestBody SearchReqDTO param){
        return searchService.basicFind(param);
    }
}
